package com.kateba.android.blueinput;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import com.kateba.android.bluetooth.BTInterface;
import com.kateba.android.ime.VirtualKeyboard;
import com.kateba.android.utils.DevUniqueID;
import com.kateba.android.utils.RGSDK4;
import com.kateba.android.utils.Settings;




public class Singleton extends Application
{
  public static final String APP_LINK = "http://www.teksoftco.com/index.php?section=product&pid=24#view";
  public static final String APP_VERSION = "2.0.209";
  public static final String CLIENT = "EU";
  public static final int ERROR_BT_NODEVS_FOUND = 0;
  public static final int ERROR_BT_SCAN = -1;
  public static final int ERROR_CONNECT_L2CAPCTRL = -2;
  public static final int ERROR_CONNECT_L2CAPINTR = -3;
  public static final int ERROR_FAILED = -1;
  public static final int ERROR_INVALID_INDEX = -1;
  public static final int ERROR_INVALID_SOCKET = -1;
  public static final int ERROR_NOERROR = 0;
  public static final int ERROR_NO_L2CAP = -4;
  public static final String FB_LINK = "http://www.facebook.com/Teksoft.Software";
  public static final String HID_PARSER = "1.0.100";
  public static final String LOG_TAG = "BlueInput::Singleton";
  public static final String PREFS_NAME = "BlueInput_PREFS";
  public static final String PRJNAME = "BlueInput";
  public static final int START_FBPAGE = 4;
  public static final int START_MINIMIZE = 1;
  public static final int START_SHARE = 3;
  public static final int START_WEBSITE = 2;
  public static final String SWID = "B102";
  static final String TEKSOFT_NORMALADS_LINK = "http://www.teksoftco.com/mobileads.php?&param=mobilenormal&pid=24&version=2.0.209";
  static final String TEKSOFT_SLIMADS_LINK = "http://www.teksoftco.com/mobileads.php?&param=mobileslim&pid=24&version=2.0.209";
  public static final int TRIAL_MAX_KEYS = 200;
  public static int clrBackgroundApp = 0;
  public static int clrBackgroundPanel = 0;
  public static int clrSubText = 0;
  public static int clrText = 0;
  public static final int clrWarningText = -65536;
  public static int g_nButPadding;
  public static int g_nSpacing;
  public static int g_nSubtitleSize;
  public static int g_nTitleSize;
  private static Singleton m_Instance;
  public static SharedPreferences prefs = null;
  public BTInterface m_BTInterf = null;
  private float m_fDensity = 0.0F;
  public GUIBlueinput m_guiInst = null;
  private int m_nScreenH = 0;
  private int m_nScreenW = 0;
  public RGSDK4 m_regObj = null;
  public Settings m_sett = null;
  public VirtualKeyboard m_vkInst = null;

  static
  {
    clrText = Color.rgb(0, 0, 0);
    clrSubText = Color.rgb(80, 80, 80);
    clrBackgroundApp = Color.rgb(100, 100, 250);
    clrBackgroundPanel = Color.rgb(230, 230, 230);
    g_nTitleSize = 18;
    g_nSubtitleSize = 14;
    g_nSpacing = 10;
    g_nButPadding = 2;
  }

  public Singleton()
  {
    m_Instance = this;
  }

  private void ReadSCR(Context paramContext)
  {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    try
    {
      WindowManager localWindowManager = (WindowManager)paramContext.getSystemService("window");
      localWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics);
      this.m_fDensity = localDisplayMetrics.density;
      this.m_nScreenW = localWindowManager.getDefaultDisplay().getWidth();
      this.m_nScreenH = localWindowManager.getDefaultDisplay().getHeight();
      Debug("ReadSCR ScrW=" + this.m_nScreenW + " ScrH=" + this.m_nScreenH + " Density=" + this.m_fDensity);
      return;
    }
    catch (Exception localException)
    {
      while (true)
      {
        Debug("SCR Exception " + localException.getMessage());
        localException.printStackTrace();
        this.m_fDensity = 0.0F;
        this.m_nScreenW = 0;
        this.m_nScreenH = 0;
      }
    }
  }

  public static Singleton getInstance()
  {
    if (m_Instance == null)
//      monitorenter;
    try
    {
      if (m_Instance == null)
        new Singleton();
//      monitorexit;
      if (prefs == null)
        prefs = m_Instance.getSharedPreferences("BlueInput_PREFS", 0);
      if (m_Instance.m_sett == null)
      {
        m_Instance.m_sett = new Settings();
        m_Instance.m_regObj = new RGSDK4();
        m_Instance.m_regObj.InitRGSDK4(DevUniqueID.GetID(), "B102");
        m_Instance.m_BTInterf = new BTInterface();
      }
      return m_Instance;
    }
    finally
    {
//      monitorexit;
    }
//    throw localObject;
	return m_Instance;
  }

  public void Debug(int paramInt, String paramString1, String paramString2)
  {
    if ((this.m_sett == null) || (!this.m_sett.getDebug()));
    while (true)
    {
     // return;
      switch (paramInt)
      {
      default:
        Log.d(paramString1, paramString2);
        break;
      case 0:
        Log.e(paramString1, paramString2);
        break;
      case 1:
        Log.w(paramString1, paramString2);
        break;
      case 2:
        Log.i(paramString1, paramString2);
        break;
      case 3:
        Log.d(paramString1, paramString2);
        break;
      case 4:
        Log.v(paramString1, paramString2);
      }
    }
  }

  public void Debug(String paramString)
  {
    Debug(3, "BlueInput::Singleton", paramString);
  }

  public void Debug(String paramString1, String paramString2)
  {
    Debug(3, paramString1, paramString2);
  }

  public int applySCRDensity(Context paramContext, int paramInt)
  {
    if (this.m_fDensity == 0.0F)
      ReadSCR(paramContext);
    return (int)(this.m_fDensity * paramInt);
  }

  public float getSCRDensity()
  {
    return this.m_fDensity;
  }

  public float getSCRDensity(Context paramContext)
  {
    if (this.m_fDensity == 0.0F)
      ReadSCR(paramContext);
    return this.m_fDensity;
  }

  public int getSCRHeight(Context paramContext)
  {
    if (this.m_nScreenH == 0)
      ReadSCR(paramContext);
    return this.m_nScreenH;
  }

  public int getSCRWidth(Context paramContext)
  {
    if (this.m_nScreenW == 0)
      ReadSCR(paramContext);
    return this.m_nScreenW;
  }

  public boolean isHdpi(Context paramContext)
  {
    if (this.m_fDensity == 0.0F)
      ReadSCR(paramContext);
    if (this.m_fDensity == 1.5D);
    for (int i = 1; ; i = 0)
      return (i==1)?true:false;
  }

  public boolean isLdpi(Context paramContext)
  {
    if (this.m_fDensity == 0.0F)
      ReadSCR(paramContext);
    if (this.m_fDensity == 0.75D);
    for (int i = 1; ; i = 0)
      return (i==1)?true:false;
  }

  public boolean isMdpi(Context paramContext)
  {
    if (this.m_fDensity == 0.0F)
      ReadSCR(paramContext);
    if (this.m_fDensity == 1.0F);
    for (int i = 1; ; i = 0)
      return (i==1)?true:false;
  }
}